package com.eu;

import com.eu.ebpm.SpringContext;
import com.eu.ebpm.engine.pvm.EngineService;
import com.eu.ebpm.engine.pvm.EngineServiceType;
import com.eu.ebpm.engine.pvm.PvmContainer;
import com.eu.mybatis.config.Dialect;
import com.eu.mybatis.config.MySql5Dialect;
import com.eu.mybatis.interceptor.EuMybatisInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import java.util.HashMap;
import java.util.Map;

@SpringBootApplication
@ComponentScan(basePackages = {"com.eu.*"})
@MapperScan({"com.eu.ebpm.engine.repository"})
public class EuEbpmApplication {
	public static void main(String[] args) {

		SpringApplication.run(EuEbpmApplication.class, args);
	}

	@Bean
    public EuMybatisInterceptor euMybatisInterceptor() {
	    EuMybatisInterceptor euMybatisInterceptor = new EuMybatisInterceptor();
	    euMybatisInterceptor.setDialect(new MySql5Dialect());
	    return euMybatisInterceptor;
    }

	@Bean
	public SpringContext springContext() {
		return new SpringContext();
	}

	@Bean
	public PvmContainer pvmContainer() {
		PvmContainer pvmContainer = new PvmContainer();
		return pvmContainer;
	}

	@Bean
	public Map<EngineServiceType, EngineService> pvmServices(
			EngineService startEventService,
			EngineService endEventService,
			EngineService userTaskService,
			EngineService serviceTaskService,
			EngineService forkBeforeService,
			EngineService forkAfterService,
			EngineService laneBeforeService,
			EngineService laneAfterService,
			EngineService laneTaskService,
			EngineService subStartEventService,
			EngineService subEndEventService
	) {
		Map<EngineServiceType, EngineService> pvmServices = new HashMap<>();
		pvmServices.put(EngineServiceType.START_EVENT, startEventService);
		pvmServices.put(EngineServiceType.END_EVENT, endEventService);
		pvmServices.put(EngineServiceType.USER_TASK, userTaskService);
		pvmServices.put(EngineServiceType.SERVICE_TASK, serviceTaskService);
		pvmServices.put(EngineServiceType.FORK_BEFORE, forkBeforeService);
		pvmServices.put(EngineServiceType.FORK_AFTER, forkAfterService);
		pvmServices.put(EngineServiceType.LANE_BEFORE, laneBeforeService);
		pvmServices.put(EngineServiceType.LANE_AFTER, laneAfterService);
		pvmServices.put(EngineServiceType.LANE_TASK, laneTaskService);
		pvmServices.put(EngineServiceType.SUB_START_EVENT, subStartEventService);
		pvmServices.put(EngineServiceType.SUB_END_EVENT, subEndEventService);
		return pvmServices;
	}

}
